#!/bin/bash
# - program
# - job

# Direct usage:
#
# job=stream.yaml tests/lkp-install-run
#
# cd tests
# program=stream ./lkp-install-run

[[ -n "$LKP_SRC" ]] || LKP_SRC=$(dirname $(dirname $(readlink -e -v $0)))

. $LKP_SRC/lib/lkp_path.sh

cd $LKP_SRC || exit
sbin/install-dependencies.sh

check_install_job()
{
	find_job "$1" || return
	local atomic_job=$(lkp split --any -o /tmp $job_file)
	atomic_job=/tmp/${atomic_job##* /tmp/}

	# don't run too long time
	sed -i 's/^\(\s*\)runtime: [0-9].*/\1runtime: 3/' $atomic_job
	sed -i 's/^\(\s*\)nr_task: [0-9].*/\1nr_task: 1/' $atomic_job
	sed -i 's/^\(\s*\)nr_threads: [0-9].*/\1nr_threads: 1/' $atomic_job
	sed -i 's/^\(\s*\)iterations: [0-9].*/\1iterations: 1/' $atomic_job
	sed -i 's/^\(\s*\)test_size: [0-9].*/\1test_size: 10M/' $atomic_job

	lkp install $atomic_job
	lkp run $atomic_job
}

if [[ -n "$program" ]]; then
	lkp install "$program"
elif [[ -n "$job" ]]; then
	check_install_job "$job"
fi
